package com.dmzc.stage1.chapter5;

import java.util.concurrent.TimeUnit;

public class EventClient1 {
    public static void main(String[] args) {
        final EventQueue1 eventQueue1 = new EventQueue1();
        for (int i = 0; i < 5; i++) {
            new Thread(() -> {
                for (; ; ) {
                    eventQueue1.offer(new EventQueue1.Event());
                }
            }, "producer" + i).start();
        }

        for (int i = 0; i < 2; i++) {
            new Thread(() -> {
                for (; ; ) {
                    eventQueue1.take();
                    try {
                        TimeUnit.MILLISECONDS.sleep(10);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
            }, "Consumer"+i).start();
        }

    }
}
